package com.donggua.aichebao.commonui.photo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import com.donggua.aichebao.photo.DGPhotoBase;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * Created by fzh on 2017/8/17.
 */

public class PhotoSelectView{
    protected DGPhotoBase mDGPhotoSelect;
    protected Activity mActivity;
    private int picNumber = 1;
    public PhotoSelectView(Activity activity) {
        mActivity = activity;
        onCreate();
    }

    public void onCreate(){
        initDGPhotoSelect();
        doShowPhoto();
    }

    public void setPicNumber(int number){
        picNumber = number;
    }

    private void initDGPhotoSelect(){
        if(mDGPhotoSelect == null){
            mDGPhotoSelect = getDGPhotoSelect("com.dg.aichebao.pickphoto.DGPhotoPick",mActivity);
            mDGPhotoSelect.setmPicNumber(picNumber);
        }
    }
    protected void doShowPhoto(){
        initDGPhotoSelect();
        mDGPhotoSelect.showPhotoPic();
    }

    public List<String> onActivityResult(int requestCode, int resultCode, Intent data){
//        initDGPhotoSelect();
        return  mDGPhotoSelect.onActivityResult(requestCode,resultCode,data);
    }

    public static DGPhotoBase getDGPhotoSelect(String clsName ,Activity activity)  {
        Object object = null;
        try {
            Class mLoadClass = Class.forName(clsName);
            Constructor constructor = mLoadClass.getConstructor(Activity.class);
            object = constructor.newInstance(activity);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return (DGPhotoBase)object;
    }
}
